// src/utils/ButtonBlot.js
import { Quill } from '@vueup/vue-quill';
const Parchment = Quill.import('parchment');
const Embed = Quill.import('blots/embed');

class ButtonBlot extends Embed {
  static create(value) {
    let node = super.create();
    node.innerHTML = value.text || '点击按钮';
    node.style.backgroundColor = value.bgColor || '#007bff';
    node.style.color = value.color || 'white';
    node.style.border = 'none';
    node.style.padding = '5px 10px';
    node.style.borderRadius = '3px';
    node.style.cursor = 'pointer';
    node.onclick = () => {
      if (value.onClick) {
        value.onClick(); // 执行传入的点击事件处理函数
      }
    };
    return node;
  }

  static value(node) {
    return {
      text: node.innerHTML,
      bgColor: node.style.backgroundColor,
      color: node.style.color,
      onClick: node.onclick
    };
  }
}

ButtonBlot.blotName = 'button';
ButtonBlot.tagName = 'BUTTON';

export default ButtonBlot;